package main

import (
	"errors"
	"fmt"
)

//快速排序
func QuickSort(i []uint32, lenght uint32) (err error) {
	if lenght <= 0 {
		return errors.New("需要排序的切片长度为空")
	}
	var (
		L, R uint32 = 0, lenght - 1
		t    uint32 = i[L]
	)
	for L < R {
		for L < R && i[R] >= t {
			R--
		}
		i[L], i[R] = i[R], i[L]
		for L < R && i[L] <= t {
			L++
		}
		i[L], i[R] = i[R], i[L]
	}

	QuickSort(i, L)
	QuickSort(i[L+1:], lenght-L-1)
	return nil
}

func main() {
	q := []uint32{4, 8, 5, 2, 9, 3, 7, 0, 6, 1, 0, 0, 8, 4, 2, 7, 6, 78, 52, 96, 35, 12}
	lenght := uint32(len(q))
	QuickSort(q, lenght)
	fmt.Println("q:", q, "\nlow:", q[0], "\nhight:", q[lenght-1])
}
